package example;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;



public class poolTest {
	
	public Collection<Cliente> listar() throws Exception{
		System.out.println("Listar");
		
		String query = "SELECT * FROM ad_mstr";
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		
		Collection<Cliente> lstClientes = new ArrayList<Cliente>();
		Cliente objCliente = new Cliente();
		
		try {
			con = conexion.obtenerConexion2();
			stmt = con.prepareStatement(query);	
			rs = stmt.executeQuery();
			while (rs.next()){
				objCliente.setCodigo(rs.getString("ad_addr"));
				objCliente.setNombre(rs.getString("ad_name"));
				lstClientes.add(objCliente);
				System.out.println(rs.getString("ad_addr") + " - " + rs.getString("ad_name"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				rs.close();
			}
			if (stmt != null) {
				stmt.close();
			}
			if (con != null) {
				con.close();
			}
		}
		
		return lstClientes;
	}

}
